package buf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

public class NettyByteBuf01 {
    public static void main(String[] args) {
        //创建bytebuf
        //1 创建对象 ，该对象包含一个数组arr，byte[10]
        //2 netty的buf不需要 filp 反转 ，因为底层维护了writeindex
        ByteBuf buffer = Unpooled.buffer(10);
        for (int i = 0; i < 11; i++) {
            buffer.writeByte(i);//每写一次增加writeindex 超过10会在自动扩容
        }
        System.out.println("数组长度= " + buffer.capacity());
        //输出
        for (int i = 0; i < buffer.capacity(); i++) {
            System.out.println(buffer.getByte(i));//getByte不会增加readindex
        }
        while (buffer.readerIndex() < buffer.capacity()){
            System.out.println(buffer.readByte());//readByte会增加readindex
        }
        //0-readindex 已经读取区域
        //readindex-writeindex可读取的区域
        //writeindex-capacity可写的区域
    }
}
